package com.huashi.dealer.modular.controller.store.active;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huashi.dealer.commonEntity.DiscountActive;
import com.huashi.dealer.core.page.PageFactory;
import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.modular.business.discount.param.DiscountActiveListParam;
import com.huashi.dealer.modular.business.discount.param.DiscountActiveSaveParam;
import com.huashi.dealer.modular.business.discount.param.DiscountActiveStateParam;
import com.huashi.dealer.modular.business.discount.service.StoreDiscountActiveService;
import com.huashi.dealer.modular.business.discount.vo.DiscountActiveDetailsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Store端优惠活动管理")
@RestController("storeActiveDiscountController")
@RequestMapping("/store/market/discount")
@Validated
public class DiscountController {

    @Resource
    private StoreDiscountActiveService storeDiscountActiveService;

    @GetMapping("/list")
    @Operation(summary = "活动列表")
    public CommonResult<Page<DiscountActive>> index(DiscountActiveListParam param) {
        Page<DiscountActive> page = PageFactory.defaultPage();
        Page<DiscountActive> result = storeDiscountActiveService.getDiscountActiveList(param, page);
        return CommonResult.data(result);
    }

    @PostMapping("/save")
    @Operation(summary = "新增或编辑活动")
    public CommonResult<String> save(@RequestBody DiscountActiveSaveParam param) {
        storeDiscountActiveService.saveOrUpdateDiscountActive(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/delete/{discountId}")
    @Operation(summary = "删除活动")
    public CommonResult<String> delete(@PathVariable Long discountId) {
        storeDiscountActiveService.deleteDiscountActive(discountId);
        return CommonResult.ok("删除成功");
    }

    @GetMapping("/details/{discountId}")
    @Operation(summary = "获取活动详情")
    public CommonResult<DiscountActiveDetailsVo> getDetails(@PathVariable Long discountId) {
        DiscountActiveDetailsVo details = storeDiscountActiveService.getDiscountActiveDetails(discountId);
        return CommonResult.data(details);
    }

    @PostMapping("/state")
    @Operation(summary = "修改活动状态")
    public CommonResult<String> updateState(@RequestBody DiscountActiveStateParam param) {
        storeDiscountActiveService.updateDiscountActiveStatus(param.getDiscountId(), param.getState());
        return CommonResult.ok("操作成功");
    }
}


